﻿@{
    ViewBag.Title = "TypeIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;

<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId", _pstructId = "", _WarehouseType = "", _ProductType = "";
    $(function () {
        InitialPage();
        GetGrid();

    });
    //初始化页面
    function InitialPage() {
        //layout布局

        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });



    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = {
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val()
        };

        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Product/GetTypeTreeListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "类别名称", name: "Name", index: "Name", width: 300, align: "center", sortable: false },
                { label: "类别编号", name: "Code", index: "Code", width: 300, align: "center", sortable: false },
                { label: "父类", name: "ParentId", index: "ParentId", width: 200, align: "center", sortable: false,hidden: true  },
                {
                    label: "有效", name: "EnabledMark", index: "EnabledMark", width: 100, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "描述", name: "Description", index: "Description", width: 100, align: "center", sortable: false }

            ],
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "Code",
            rowNum: "all",
            rownumbers: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow'); 
            },
            gridComplete: function () { 
                $("#" + this.id).setSelection(selectedRowIndex, false); 
            }
        }); 
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            };
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_Product/GetTypeTreeListJson",
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');

        });



    }
    //新建类别
    function btn_add() {
        dialogOpen({
            id: "TypeForm",
            title: '新建类别',
            url: '/ResourceManage/RS_Product/TypeForm',
            width: "500px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //编辑
    function btn_edit3() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "TypeForm",
                title: '修改类别信息',
                url: '/ResourceManage/RS_Product/TypeForm?keyValue=' + keyValue,
                width: "500px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })

        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: '/ResourceManage/RS_Product/RemoveTypeForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td style="padding-left: 2px;">
                    <div class="btn-group" id="queryCondition">
                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a data-value="Code">编号</a></li>
                            <li><a data-value="Name">名称</a></li>
                        </ul>
                    </div>
                </td>
                <td>
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-addItem" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-editItem" class="btn btn-default" onclick="btn_edit3()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-deleteItem" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
</div>
